from enetity_extraction.json_result import generate_return_json


def is_valid_serial_number(date_dic):
    result = generate_return_json()

    if date_dic['正文序号'] == [] or date_dic['正文序号'] == {}:
        result['type'] = '正文序号缺失'
        # return result
        return None

    # 有多个，所以是列表，
    # 如果是正确的，也不会返回 字符位置，因为有多个

    # 所以也给多个错误列表
    # result['paragraph_index'] = []
    # result['start'] = []
    # result['end'] = []

    data_list = date_dic['正文序号']
    for item in data_list:
        if any(char.isdigit() for char in item['match']):
            # result赋值
            result['paragraph_index'] = item['paragraph_index']
            result['start'] = item['start_pos']
            result['end'] = item['end_pos']
            # print('正文序号不应该有数字')
            result['type'] = '正文序号不应该有阿拉伯数字'
            result['offset'] = item['end_pos'] - item['start_pos'] + 1
            return result

    result['type'] = '正文序号合法'
    # return result
    # return None
